package cn.wolfcode.car.business.web.controller;
import cn.wolfcode.car.business.domain.CustomerLinkMane;
import cn.wolfcode.car.business.domain.CustomerVisit;
import cn.wolfcode.car.business.query.CustomerVisitQuery;
import cn.wolfcode.car.business.service.ICustomerLinkManeService;
import cn.wolfcode.car.business.service.ICustomerService;
import cn.wolfcode.car.business.service.ICustomerVisitService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/business/customerVisit")
public class CustomerVisitController {

    private static final String prefix = "business/customerVisit/";

    @Autowired
    private ICustomerVisitService customerVisitService ;
    @Autowired
    private ICustomerService customerService;
    @Autowired
    private ICustomerLinkManeService customerLinkManeService;

    //列表
    @RequestMapping("/listPage")
    public String listPage(){
        return prefix + "list";
    }

    //添加页面
    @RequestMapping("/addPage")
    public String addPage(Model model){
        model.addAttribute("customer", customerService.selectAll());
        return prefix + "add";
    }

    @RequestMapping("/customerVisitQuery")
    @ResponseBody
    public TablePageInfo<CustomerVisit> customerVisitQuery(CustomerVisitQuery qo){
        return customerVisitService.query(qo);
    }

    //新增
    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CustomerVisit customerVisit ){
        customerVisitService.save(customerVisit);
        return AjaxResult.success();
    }

    //客户联系人查询
    @RequestMapping("/customerBylinkman")
    @ResponseBody
    public AjaxResult customerBylinkman(Long id,Model model){
        List<CustomerLinkMane> customerLinkManes = customerVisitService.customerBylinkman(id);
        return AjaxResult.success(customerLinkManes);
    }

}
